# -*- coding:utf-8 -*-
"""
Author：Administrator
Date:2021年12月23日
"""
from sklearn.svm import LinearSVR
from sklearn.datasets import load_boston
from pandas import DataFrame

boston = load_boston()  # 创建加载波士顿的数据对象
df = DataFrame(boston.data, columns=boston.feature_names)
df.insert(0, 'target', boston.target)
data_mean = df.mean()
data_std = df.std()
data_train = (df - data_mean) / data_std  # 数据标准化
x_train = data_train[boston.feature_names].values
y_train = data_train['target'].values
linearsvr = LinearSVR(C=0.1)
linearsvr.fit(x_train, y_train)
# 预测,并还原结果
x = ((df[boston.feature_names] - data_mean[boston.feature_names]) / data_std[boston.feature_names]).values
# 添加预测房价的信息列
df[u'y_pred'] = linearsvr.predict(x) * data_std['target'] + data_mean['target']
print(df[['target', 'y_pred']].head())

